package 代码记录.校招笔试真题.笔试真题_2022.去哪儿网;

public class Test1 {
    /**
     * @return 这个题很重要
     */
    public int maxScore (int energy, int[][] actions) {
        int res = 0;//最大子序和
        int[] dp = new int[actions.length];
        boolean[] flag = new boolean[actions.length];
        dp[0] = actions[0][1];
        res = dp[0];
        for(int i = 1;i < dp.length;i++){
            dp[i] = Math.max(dp[i - 1],dp[i - 1] + actions[i][1]);
            if(dp[i] != dp[i - 1]){//zuo
                energy -= actions[i][0];
            }
            if(energy > 0) flag[i] = true;
            if(flag[i] == true && dp[i] > res){
                res = dp[i];
            }

        }
        return res;
    }
}
